package day.day7_17;
import java.util.*;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str1 = sc.nextLine();
        String str2 = sc.nextLine();
        //判断两个字符串谁长谁短
        if (str1.length() <= str2.length()) {
            compare(str1, str2);
        } else {
            compare(str2, str1);
        }
    }

    public static void compare(String str1, String str2) {
        String result = "";
        for(int i =1;i<str1.length();i++){
            StringBuilder stringBuilder = new StringBuilder();
            for(int j =i-1;j<str1.length();j++){
                if(str2.contains(stringBuilder.append(str1.charAt(j)))){
                    if(stringBuilder.length() > result.length()){
                        result = stringBuilder.toString();
                    }
                }
            }
        }
        System.out.println(result);
    }
}
